package archsw0904.model;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name="Book")
@NamedQueries({
	@NamedQuery	(name="getAll", query = "SELECT OBJECT(obj) FROM Book obj"),
	@NamedQuery(name="Book.findBookIsbn", query="SELECT OBJECT(obj) FROM Book obj WHERE obj.isbn = :isbn"),
	@NamedQuery(name="Book.shopWindowBook", query="SELECT OBJECT(obj) FROM Book obj WHERE obj.shopWindow = TRUE")
})
//@NamedQuery
public class Book implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int id;
	private String isbn = "";
	private String author = "";
	private String title = "";
	private String category = "";
	private String tag = ""; 
	private BigDecimal price =  new BigDecimal(0);
	private String editor = "";
	private Integer availableCopies = 0;
	private Integer CopiesInStockroom = 0;
	private String year;
	private boolean shopWindow = false;
	
	public Book() {
		super();
	}
	
	@Id
	@GeneratedValue
	public int getId() {
		return this.id;
	}
	public void setId(int id) {
		this.id= id;
	}
	
	@Column(unique=true)
	public String getIsbn() {
		return isbn;
	}
	
	public void setIsbn(String isbn) {
		this.isbn = isbn.toLowerCase();
	}
	
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author.toLowerCase();
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category.toLowerCase();
	}
	public String getTag() {
		return tag;
	}
	public void setTag(String tag) {
		this.tag = tag.toLowerCase();
	}
	public BigDecimal getPrice() {
		return price;
	}
	public void setPrice(BigDecimal price) {
		this.price = price;
	}
	public String getEditor() {
		return editor;
	}
	public void setEditor(String editor) {
		this.editor = editor.toLowerCase();
	}
	
	
	public String getTitle() {
		return this.title;
	}
	public void setTitle(String title) {
		this.title = title.toLowerCase();
	}
	
	public void setAvailableCopies(Integer availableCopies) {
		this.availableCopies = availableCopies;
	}

	public Integer getAvailableCopies() {
		return availableCopies;
	}
	
	public void addAvailableCopies(Integer num){
		availableCopies = availableCopies+num;
	}
	
	public void decAvailableCopies(Integer num){
		availableCopies = availableCopies-num;
	}

	public void setCopiesInStockroom(Integer copiesInStockroom) {
		CopiesInStockroom = copiesInStockroom;
	}

	public Integer getCopiesInStockroom() {
		return CopiesInStockroom;
	}

	public void setShopWindow(boolean shopWindow) {
		this.shopWindow = shopWindow;
	}

	public boolean isShopWindow() {
		return shopWindow;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getYear() {
		return year;
	}

}
